﻿@model List<Comment>
    @using NITASA.Data
    @using GridMvc.Html
    @{
        ViewBag.Title = "Comments";
    }
    <div class="main-content">
        <div class="container-fluid padded">
            <div class="row-fluid">
                <div class="span12">
                    <div class="box">
                        <div class="box-header">
                            <ul class="nav nav-tabs nav-tabs-left">
                                <li class="active"><a href="@Url.Action("List", "Comment")">All Comments</a></li>
                                <li><a href="@Url.Action("Abusive", "Comment")">Abusive Comments</a></li>
                            </ul>
                        </div>
                        <div class="box-content padded">
                            <div class="tab-content">
                                <div class="tab-pane active">
                                    <div class="row-fluid">
                                        <div class="span12">
                                            @if (Model.Count() > 0)
                                            {
                                                <div class="box">
                                                    <div class="box-content">
                                                        @Html.Grid(Model).Columns(columns =>
                                                       {
                                                           columns.Add(x => x.UserName).Titled("Name").Sortable(true).Filterable(true).SetWidth(100);
                                                           columns.Add(x => x.Description).Titled("Comment").Sortable(true).Filterable(true).SetWidth(500);
                                                           columns.Add(x => x.Content.Title).Titled("Posts/Page").Sortable(true).Filterable(true);
                                                           columns.Add(x => x.AddedOn).Titled("Commented On").Format("{0:MMM d, h:mm tt}").Sortable(true).Filterable(true).SetWidth(40);
                                                           columns.Add(x => x.IsModerated).Encoded(false).Sanitized(false).Titled("Display").RenderValueAs(x =>
                                                               @Html.Raw("<input type=\"checkbox\" class =\"iButton-icons\" data-id=\"" + x.ID + "\" " + (x.IsModerated == true ? "checked=checked" : "") + " />")).SetWidth(50);
                                                       }).WithPaging(10, 5).WithMultipleFilters()
                                                    </div>
                                                </div>
                                            }
                                            else
                                            {
                                                <div class="padded">
                                                    No Comments Found.
                                                </div>
                                            }
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <script>
        $(document).ready(function () {
            $(".iButton-icons").iButton(
            {
                labelOn: '<i class="icon-ok"></i>',
                labelOff: '<label><i class="icon-remove"></i></label>',
                change: function ($input) {
                    $.ajax({
                        url: "@Url.Action("ChangeStatus", "Comment")",
                        data: { id: $($input).attr("data-id"), status: $($input).prop('checked') }
                    });
                }
            });
        });
    </script>
